package com.tool.grab.vpn;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.tool.grab.Logs;

public class VPNManager {
    private final static String TAG = VPNManager.class.getSimpleName();
    private static VPNManager manager;
    private HttpVPNService service;

    private VPNManager(){}

    public static VPNManager Instance(){
        if(manager == null){
            manager = new VPNManager();
        }
        return manager;
    }

    public void startService(Context context){
        Intent intent = HttpVPNService.prepare(context);

        if(intent != null){
            if(context instanceof Activity){
                ((Activity)context).startActivityForResult(intent,0);
            }else{
                Logs.i(TAG,"初始化VPN失败");
            }
        }else{
            Intent intent1 = new Intent(context,HttpVPNService.class);
            context.startService(intent1);
        }
    }

    public static void stopService(){
        if(manager == null || manager.service == null || !manager.service.isRun()){
            // 非运行状态
        }else{
            manager.service.stopSelf();
        }

        if(manager != null){
            manager.service = null;
        }
    }

    public void setService(HttpVPNService service){
        this.service = service;
    }




}
